##############################################################
#Figure C7: Distribution of Risk Aversion and Age in CCES 2014
##############################################################

data <- read.dta("./input/cces-subset.dta")

smalld <- data[,c("employed", "out_of_labour", "race_14", "risk", "dem14", "education", 
                  "female", "income", "income_quarters", "age")]

smalld$income <- as.factor(smalld$income)
smalld$income_quarters <- as.factor(smalld$income_quarters)
smalld$education <- as.factor(smalld$education)

data6 <- smalld

data6$risk <- as.factor(data6$risk)

ggplot(data6, aes(age, fill=risk)) + 
  geom_density(alpha=.5) + 
  theme_classic() + 
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.ticks.length=unit(0.25,"cm")) + 
  xlab("Age") + ylab("Density") + 
  scale_y_continuous(breaks = c(0,0.01,0.02,0.03,0.04,0.05), limits=c(0,0.05), expand=c(0,0)) + 
  scale_x_continuous(breaks = c(20,40,60,80,100), limits=c(20,100), expand=c(0,0)) + 
  scale_fill_manual(values=c("black", "grey60", "goldenrod1", "darkgoldenrod4"), 
                    labels=c("Taker", "Neutral-Tk", "Neutral-Av", "Averse") , name="Risk Aversion Level")

ggsave("./figures/figc7.pdf")
